package CountDownLatch;

import java.util.concurrent.CountDownLatch;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        //假设10个选手跑步比赛
        CountDownLatch countDownLatch = new CountDownLatch(10);
        for(int i = 0; i < 10; i++) {
            Thread t = new Thread(() -> {
                System.out.println("选手" + Thread.currentThread().getName() + "开始跑步");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("选手" + Thread.currentThread().getName() + "到达终点");
                //撞线
                countDownLatch.countDown();
            });
            t.start();
        }
        //等待10名选手都撞线后，比赛就结束了，当然await也可以带参数
        countDownLatch.await();
        System.out.println("终止程序");
    }
}
